package com.manong.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.manong.aspect.AutoFill;
import com.manong.entity.ActionLog;
import com.manong.entity.LoginLog;
import com.manong.service.ActionLogService;
import com.manong.utils.Result;
import com.manong.vo.query.ActionLogVo;
import com.manong.vo.query.LoginLogQueryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/action")
public class AtcionLogController {
    @Resource
    private ActionLogService actionLogService;

    /**
     * 分页查询操作日志
     * @param actionLogVo
     * @return
     */
    @GetMapping("/list")
    public Result list(ActionLogVo actionLogVo){
        IPage<ActionLog> page = new Page<ActionLog>();
        page.setCurrent(actionLogVo.getPageNo());
        page.setSize(actionLogVo.getPageSize());
        actionLogService.findActionListByUsername(page,actionLogVo);
        return Result.ok(page);
    }

    /**
     * 批量删除操作日志
     * @param ids
     * @return
     */
    @AutoFill(menu = "操作日志", type = "删除")
    @DeleteMapping("/delete/{ids}")
    @PreAuthorize("hasAuthority('sys:actionlog:delete')")
    public Result delete(@PathVariable List<Long> ids){

        if(actionLogService.delete(ids)){
            return Result.ok().message("删除成功");
        }else {
            return Result.error().message("删除失败");
        }
    }
}
